package com.controller.sys;


import com.common.Result;
import com.common.log.OperationLog;
import com.common.log.OperationType;
import com.entity.sys.Menu;
import com.service.sys.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author clay
 * @since 2022-02-15
 */
@Api("MenuController")
@RestController
@RequestMapping("/sys/menu")
public class MenuController extends BaseController {

    @Autowired
    private MenuService menuService;

    @ApiOperation(value = "通过用户ID查询菜单列表")
    @GetMapping("/getMenuByUserId")
    public Result getMenuByUserId() {
        return Result.success(menuService.getMenuByUserId());
    }

    @ApiOperation(value = "添加菜单")
    @PostMapping("/add")
    @OperationLog(operationType = OperationType.INSERT, describe = "添加菜单", entity = Menu.class, primaryKey = "")
    public Result add(@RequestBody Menu menu) {
        return Result.success(menuService.save(menu));
    }

    @ApiOperation(value = "删除菜单")
    @GetMapping("/delete/{id}")
    @OperationLog(operationType = OperationType.DELETE, describe = "添加菜单", entity = Menu.class, primaryKey = "")
    public Result delete(@PathVariable String id) {
        return Result.success(menuService.deleteMenu(id));
    }

    @ApiOperation(value = "修改菜单")
    @PostMapping("/update")
    @OperationLog(operationType = OperationType.DELETE, describe = "添加菜单", entity = Menu.class, primaryKey = "")
    public Result update(@RequestBody Menu menu) {
        return Result.success(menuService.updateById(menu));
    }

    @ApiOperation("通过id获取菜单信息")
    @GetMapping("/info/{id}")
    public Result info(@PathVariable String id) {
        return Result.success(menuService.getById(id));
    }


    @ApiOperation("获取所有list")
    @GetMapping("/list")
    public Result list() {
        return Result.success(menuService.getList());
    }

}
